<template>
  <div class="">

    <Table :columns="columns" :data="tableData" :loading="loading"></Table>
    <Page size="small" class="m-t-5px float-right" :total="pageTotal" :current.sync="pageIndex" :page-size="pageSize"
          show-elevator show-total @on-change="loadEnshrineComps">
    </Page>

  </div>
</template>

<script>
  import ManageMixin from "../../../../mixin/ManageMixin";

  export default {
    name: 'EnshrineCompTableExpand',
    mixins: [ManageMixin],
    props: {
      enshrineCompGroupId: {
        type: String,
        require: true
      }
    },
    data() {
      return {
        loading: false,
        columns: [
          {
            title: '缩略图',
            align: 'center',
            render: (h, params) => {
              return h('div', [
                h('img', {
                  attrs: {
                    src: this.thumbnailPath(params.row.thumbnail_uri)
                  },
                  style: {
                    width: '85px',
                    height: '50px',
                    marginTop: '5px',
                    backgroundColor: '#616161',
                    borderRadius: '4px',
                    padding: '5px'
                  },
                  on: {

                  }
                })
              ]);
            }
          },
          {
            title: '收藏名称',
            key: 'enshrine_name'
          },
          {
            title: '组件名称',
            key: 'component_name'
          },
          {
            title: '备注',
            key: 'remark'
          },
          {
            title: '创建日期',
            key: 'create_date',
            width: 170
          },
          {
            title: '操作',
            key: 'action',
            width: 150,
            align: 'center',
            render: (h, params) => {
              return h('div', [
                /*h('Button', {
                  props: {
                    size: 'small',
                    type: 'primary',
                    icon: 'md-create'
                  },
                  'class': {
                    'm-r-5px': true
                  },
                  on: {
                    click: () => {
                      this.openCompinfoForm('update', params.row)
                    }
                  }
                }),*/
                h('Poptip', {
                  props: {
                    confirm: true,
                    transfer: true,
                    title: '您确定要删除此项吗？'
                  },
                  style: {

                  },
                  on: {
                    'on-ok': () => {
                      this.deleteEnshrineComp(params.row.id)
                    }
                  }
                }, [
                  h('Button', {
                    props: {
                      size: 'small',
                      type: 'error',
                      icon: 'md-trash'
                    }
                  },)
                ])
              ]);
            }
          }
        ]
      }
    },
    mounted() {
      this.loadEnshrineComps()
    },
    methods: {

      loadEnshrineComps () {
        this.loading = true
        this.$PnApi.EnshrineCompApi.getEnshrineCompByPage(this.pageIndex, this.pageSize, this.enshrineCompGroupId).then(result=>{
          this.tableData = result.data.payload.list;
          this.pageTotal = result.data.payload.total;
          this.loading = false
        })
      },

      deleteEnshrineComp (id) {
        this.$PnApi.EnshrineCompApi.deleteEnshrineComp(id).then(result => {
          if(result.data.success) {
            this.loadEnshrineComps();
            this.$Message.success(result.data.message)
          }
        })
      },

      thumbnailPath (thumbnail_uri) {
        if (thumbnail_uri) {
          try {
            return require('../../../../components/functional/'+thumbnail_uri)
          }catch (e) {
            return ''
          }
        }else {
          return require('@/assets/image/thumbnail/thumbnail-default.png')
        }
      },

    },
    computed: {}
  }
</script>

<style scoped>

</style>
